import execjs
# todo AES 解密
# todo BASE64_1


class MyCropto():
    def __init__(self):
        node = execjs.get()
        fp = open("myCrypto.js", "r", encoding="utf-8")
        self.ctx = node.compile(fp.read())
    def aes_Encrypt(self,word,key,iv):
        return self.ctx.eval(f'AES_Encrypt("{word}","{key}","{iv}")')

    def aes_Decrypt(self,word,key,iv):
        return self.ctx.eval(f'AES_Decrypt("{word}","{key}","{iv}")')
    def base64_Encrypt(self,word):
        return self.ctx.eval(f'crypto_Base64("{word}")')
    def base64_Decrypt(self,word):
        return self.ctx.eval(f'cryptoBase64("{word}")')
    def md5_Encrypt(self,word):
        return self.ctx.eval(f'cryptoMD5("{word}")')
    def sha1_Encrypt(self,word):
        return self.ctx.eval(f'cryptoSHA1("{word}")')
    def sha224_Encrypt(self,word):
        return self.ctx.eval(f'cryptoSHA224("{word}")')

    def sha256_Encrypt(self, word):
        return self.ctx.eval(f'cryptoSHA256("{word}")')
    def sha384_Encrypt(self, word):
        return self.ctx.eval(f'cryptoSHA384("{word}")')
    def sha512_Encrypt(self,word):
        return self.ctx.eval(f'cryptoSHA512("{word}")')
# my=MyCropto()
# print(f'AES解密：{my.aes_Decrypt("eo7Yz7nc8ChCYUlJkV4AiGZICEbN6qVyd8RaxtcMo3YSs6xvsKHOAy/kwpwJIzmC50EbuuhsMvswgvkosFy2Vg==","y42hjx3dsv838sxu", "y42hjx3dsv838sxu")}')
# print(f'AES加密：{my.aes_Encrypt("start_180.106.165.50, 172.27.39.201_XW_2024-10-18","y42hjx3dsv838sxu", "y42hjx3dsv838sxu")}')
# print(f'BASE64加密：{my.base64_Encrypt("123")}')
# print(f'BASE64解密：{my.base64_Decrypt("MTIz")}')
# print(f'sha1加密：{my.sha1_Encrypt("123")}')
# print(f'sha224加密：{my.sha224_Encrypt("123")}')
# print(f'sha256加密：{my.sha256_Encrypt("123")}')
# print(f'sha384加密：{my.sha384_Encrypt("123")}')
# print(f'sha512加密：{my.sha512_Encrypt("123")}')